<!doctype html>
<title>setTimeout/setInterval with throwing code</title>
<link rel="author" title="Sebstian Mayr" href="mailto:wpt@smayr.name">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
"use strict";
setup({ allow_uncaught_exception: true });

promise_test(() => {
  return new Promise(resolve => {
    setTimeout("throw new Error('test1')", 10);

    window.onerror = message => {
      window.onerror = null;

      assert_equals(message, "test1");

      resolve();
      return true;
    };
  });
}, "setTimeout, string argument");

promise_test(() => {
  return new Promise(resolve => {
    setTimeout(() => {
      throw new Error("test2");
    }, 10);

    window.onerror = message => {
      window.onerror = null;

      assert_equals(message, "test2");

      resolve();
      return true;
    };
  });
}, "setTimeout, function argument");

promise_test(() => {
  return new Promise(resolve => {
    const i = setInterval("throw new Error('test3')", 10);

    window.onerror = message => {
      window.onerror = null;
      clearInterval(i);

      assert_equals(message, "test3");

      resolve();
      return true;
    };
  });
}, "setInterval, string argument");

promise_test(() => {
  return new Promise(resolve => {
    const i = setInterval(() => {
      throw new Error("test4");
    }, 10);

    window.onerror = message => {
      window.onerror = null;
      clearInterval(i);

      assert_equals(message, "test4");

      resolve();
      return true;
    };
  });
}, "setInterval, function argument");
</script>
